// JavaScript Document

function checkEmailAddr(email){
	var pattern = /^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}(\.[a-zA-Z]{2,3}){0,1}$/;
	return pattern.test(email);
}

$(window).load(function() {
    $('#slider').nivoSlider({
		pauseTime: 10000,
		directionNav: false
	});
	
	$('#btn-confirm-ok').click(function(e) {
        $('#confirm-window').hide();
    });
	
	$('#btn-prompt-ok').click(function(e) {
        $('#prompt-window').hide();
    });
	
	$('#txt-search').focusin(function(e) {
        if($(this).val() == 'Mã sản phẩm')
			$(this).val('');
    });
	
	$('#txt-search').focusout(function(e) {
        if($(this).val() == '')
			$(this).val('Mã sản phẩm');
    });
});

function booking(id, code, name, price){
	$(document).ready(function(e) {
        $.ajax({
			url : 'ajax_booking.php',
			type : 'POST',
			data : {
				act : 'add',
				id : id,
				code : code,
				name : name,
				price : price
			},
			success : function(data){
				$('#cart_qty').text(data);
				showAlert('Thông báo', 'Đã thêm sản phẩm vào giỏ hàng', '');
			},
			error : function(XMLHttpRequest, textStatus, errorThrown){
				
			}
		});
    });
}

function clearCart(){
	$(document).ready(function(e) {
        $.ajax({
			url : 'ajax_booking.php',
			type : 'POST',
			data : {
				act : 'clr'
			},
			success : function(data){
				$('#cart_qty').text(data);
				location.reload();
			},
			error : function(XMLHttpRequest, textStatus, errorThrown){
				
			}
		});
    });
}

function showAlert(title, message, focusId){
	$(document).ready(function(e) {
		$('#btn-alert-ok').attr('focusid', focusId);
        $('#alert-title').text(title);
		$('#alert-content').text(message);
		$('#alert-window').show();
    });
}

function hideAlert(){
	$(document).ready(function(e) {
		$('#alert-window').hide();
		var idToFocus = $('#btn-alert-ok').attr('focusid');
		if(idToFocus != '')
			$('#'+idToFocus).focus();
	});
}

function showConfirm(title, message, yesFunc){
	$(document).ready(function(e) {
		yesFunc = yesFunc.replace(/\[/g,"'");
		yesFunc = yesFunc.replace(/\]/g,"'");
		$('#btn-confirm-ok').attr('onclick', yesFunc);
        $('#confirm-title').text(title);
		$('#confirm-content').text(message);
		$('#confirm-window').show();
    });
}

function hideConfirm(){
	$(document).ready(function(e) {
        $('#confirm-window').hide();
    });
}

function showPrompt(title, message, defVal, yesFunc){
	$(document).ready(function(e) {
		yesFunc = yesFunc.replace(/\[/g,"'");
		yesFunc = yesFunc.replace(/\]/g,"'");
		$('#btn-prompt-ok').attr('onclick', yesFunc);
        $('#prompt-title').text(title);
		$('#prompt-content').text(message);
		$('#prompt-val').val(defVal);
		$('#prompt-window').show();
		$('#prompt-val').focus();
    });
}

function hidePrompt(){
	$(document).ready(function(e) {
        $('#prompt-window').hide();
    });
}




